package com.by.controller;

import com.by.com.dao.bean.PageResult;
import com.by.common.core.bean.ResultBean;
import com.by.common.core.controller.BaseController;
import com.by.common.token.TokenTemplate;
import com.by.entity.User;
import com.by.query.UserQuery;
import com.by.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sys")
@Api(tags = "用户管理")
public class UserController extends BaseController {

    @Autowired
    UserService userService;
    //@Autowired(required = false) 时，务必确保代码中有适当的空值检查逻辑，以避免 NullPointerException
    @Autowired(required = false)
    TokenTemplate tokenTemplate;
    @PostMapping("/user")
    public ResultBean save(@RequestBody User user){
        int rs=userService.saveEntity(user);
        return saveResult(rs);
    }

    @GetMapping("/user")
    public ResultBean<PageResult> query(UserQuery query){
        PageResult result=userService.query(query);
        return success("用户列表",result);
    }
}
